package com.yang.net.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.*;

/**
 * @author yds
 * @program net-sokect_stduy
 * @description 作为udp协议消息发送方
 * @create 2020-10-09 09:06
 **/
public class UdpSender {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket();
        while(true) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String msg = reader.readLine();
            DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, InetAddress.getByName("localhost"), 9000);
            socket.send(packet);
            if ("bye".equals(msg)) {
                break;
            }
        }
        socket.close();
    }

}